*-------------------------------------------------------------------------------
* PROGRAM: Explore effect of certificate ownership on disputes and farm capital in Uganda LSMS
* CODER : Sarah Walker
* DATE: 8/22/2024
*-------------------------------------------------------------------------------

set more off
clear all
capture log close 
set maxvar 32000
set matsize 10000

*Setting correct dropbox location
version 14

local 	sel_user		1		

if `sel_user'			== 1 {
* Allow for Windows or Mac operating systems
if c(os) == "Windows" {
    local prefix "C:"
	}
else if c(os) == "MacOSX" {
    local prefix ""
	}
	
* Find the right Dropbox main folder
if c(os) == "Windows" {
	cap cd "C:/Users/`c(username)'/Dropbox/Sarah's Folders/UNSW/Projects/Uganda/" /* Sarah's Desktop */

}
else if c(os) == "MacOSX" {
    cap cd "/Users/`c(username)'/Dropbox/Sarah's Folders/UNSW/Projects/Uganda/" /*Sarah's Mac*/
   
}

global dropbox `c(pwd)'
global lsms "$dropbox/UgandaPESShareFolder/UgandaLandTenure/Data/LSMS"

global household15 "$lsms/LSMS 2015/UGA_2015/AGSEC1.dta"
global owner15 "$lsms/LSMS 2015/UGA_2015/AGSEC2A.dta"
global user15 "$lsms/LSMS 2015/UGA_2015/AGSEC2B.dta"
global tenure "$dropbox/UgandaPESShareFolder/UgandaLandTenure/Data/tenure_census_district.dta" // district level tenure from 2002


}


	if 		`sel_user'		== 2 {
global dropbox  "C:\Users\alixgarj\Dropbox"

global lsms "$dropbox\UgandaPESShareFolder\UgandaLandTenure\Data\LSMS"

global household15 "$lsms\LSMS 2015\UGA_2015\AGSEC1.dta"
global owner15 "$lsms\LSMS 2015\UGA_2015\AGSEC2A.dta"
global user15 "$lsms\LSMS 2015\UGA_2015\AGSEC2B.dta"
global tenure "$dropbox/UgandaPESShareFolder/UgandaLandTenure/Data/tenure_census_district.dta" // district level tenure from 2002		
		
		
	}


global treetablesuganda "$path/Outputs/Trees Experiment/Tables"



********************************************************************************
* MERGING DATA
********************************************************************************
* Fix dispute data from 2005 for later merging*
use "$lsms/LSMS 2005/UGA_2005/2005_AGSEC9.dta", clear
ren A9q1 parcelid
drop if parcelid==.
g year_wave=2005
local filename = "lsms_dispute_2005"
save  `filename', replace

* 2005 and 2009 *
foreach i in 2005 2009 {
	
	use "$lsms/LSMS `i'/UGA_`i'/`i'_GSEC1.dta", clear // HH data
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/`i'_AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	*destring HHID, replace
	g year_wave=`i'
	g own=1
	local filename = "lsms_own_`i'"
	save  `filename', replace
	
	use "$lsms/LSMS `i'/UGA_`i'/`i'_GSEC1.dta", clear // HH data
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/`i'_AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	*destring HHID, replace
	g year_wave=`i'
	g user=1
	local filename = "lsms_user_`i'"
	save  `filename', replace
	
}


* 2010/11 and 2011/12 *
foreach i in 2010 {

	use "$lsms/LSMS `i'/UGA_`i'/GSEC1.dta", clear // HH data	
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	g year_wave=`i'
	g own=1
	g title=.
	replace title = a2aq25 if year_wave==2010
	replace title = a2aq23 if year_wave==2011
	ren h1aq1 district_name	
	local filename = "lsms_own_`i'"
	save  `filename', replace
	
	use "$lsms/LSMS `i'/UGA_`i'/GSEC1.dta", clear // HH data	
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	g year_wave=`i'
	g user=1
	ren h1aq1 district_name	
	local filename = "lsms_user_`i'"
	save  `filename', replace
}


foreach i in 2011 {

	use "$lsms/LSMS `i'/UGA_`i'/GSEC1.dta", clear // HH data	
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	tostring(HHID), gen(temph) format("%20.0g")
	drop HHID
	gen HHID = temph
	g year_wave=`i'
	g own=1
	g title=.
	replace title = a2aq25 if year_wave==2010
	replace title = a2aq23 if year_wave==2011
	ren h1aq1 district_name	
	local filename = "lsms_own_`i'"
	save  `filename', replace
	
	use "$lsms/LSMS `i'/UGA_`i'/GSEC1.dta", clear // HH data	
	merge 1:m HHID using "$lsms/LSMS `i'/UGA_`i'/AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	tostring(HHID), gen(temph) format("%20.0g")
	drop HHID
	gen HHID = temph
	g year_wave=`i'
	g user=1
	ren h1aq1 district_name	
	local filename = "lsms_user_`i'"
	save  `filename', replace
}




* 2013/14 *
foreach i in 2013 {
	
	use "$lsms/LSMS 2013/UGA_2013/AGSEC1.dta", clear // HH data
	merge 1:m hh using "$lsms/LSMS 2013/UGA_2013/AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	g year=year_v1
	g year_wave=`i'
	g own=1
	g title = a2aq23
	drop HHID
	g HHID = substr(hh,1,6) + substr(hh,11,2)
	local filename = "lsms_own_`i'"
	save  `filename', replace	
	
	
	use "$lsms/LSMS 2013/UGA_2013/AGSEC1.dta", clear // HH data
	merge 1:m hh using "$lsms/LSMS 2013/UGA_2013/AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	g year=year_v1
	destring year, replace
	g year_wave=`i'
	g user=1
	drop HHID
	g HHID = substr(hh,1,6) + substr(hh,11,2)
	local filename = "lsms_user_2013"
	save  `filename', replace
	
}

* 2015/16 *
	use "$lsms/LSMS 2015/UGA_2015/AGSEC1.dta", clear // HH data
	merge 1:m HHID using "$lsms/LSMS 2015/UGA_2015/AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	g year_wave=2015
	g own=1
	g title = a2aq23
	local filename = "lsms_own_2015"
	save  `filename', replace	
	
	use "$lsms/LSMS 2015/UGA_2015/AGSEC1.dta", clear // HH data
	merge 1:m HHID using "$lsms/LSMS 2015/UGA_2015/AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	g year_wave=2015
	g user=1
	local filename = "lsms_user_2015"
	save  `filename', replace
	

 *2018/19 - only new parcels *
	use "$lsms/LSMS 2018 v2/HH/GSEC1.dta", clear // HH data	
	merge 1:m hhid using "$lsms/LSMS 2018 v2/Agric/AGSEC2A.dta" // owner data
	keep if _m==3
	drop _m
	g year_wave=2018
	g own=1
	ren distirct_name district_name
	ren s2aq7 tenure_own_2018 // Tenure only asked for new parcels!
	g title = s2aq23 
	g yearoftitle = a2aq31
	*ren hhid HHID
	*tostring HHID, replace	
	g HHID = t0_hhid
	local filename = "lsms_own_2018"
	save  `filename', replace
	
	use "$lsms/LSMS 2018 v2/HH/GSEC1.dta", clear // HH data	
	merge 1:m hhid using "$lsms/LSMS 2018 v2/Agric/AGSEC2B.dta" // user data
	keep if _m==3
	drop _m
	g year_wave=2018
	g user=1
	*g title = s2aq23  // this question seems not to be asked for users. why?
	ren distirct_name district_name
	ren s2aq07 tenure_user_2018 // Tenure only asked for new parcels!
	*ren hhid HHID
	*tostring HHID, replace	
	g HHID = t0_hhid
	local filename = "lsms_user_2018"
	save  `filename', replace

	
* Append all waves *
append using lsms_own_2018, force

foreach i in 2005 2009 2010 2011 2013 2015 {
	append using lsms_own_`i', force
	append using lsms_user_`i', force
}


tab year_wave

tempfile lsms
save `lsms'


*---------------------------------------------------------------------
* Add equipment info
*---------------------------------------------------------------------

* 2011
use "$lsms/LSMS 2011/UGA_2011/AGSEC10.dta", clear 

tostring(HHID), gen(temph) format("%20.0g")
drop HHID
gen HHID = temph
g year_wave = 2011

g capital = (a10q1==2 | a10q1==6 | a10q1==10 | a10q1==15 | a10q1==16 | a10q1==17 | a10q1==18 )
// plough, tractor, chain saw, trailer, cultivator, weeder, planter

bysort HHID: egen farm_capital = sum(a10q1)
bysort HHID: egen heavy_capital = sum(capital)

duplicates drop HHID, force

keep HHID year_wave farm_capital heavy_capital

tempfile w2011
save `w2011'
	
* 2013-14
use "$lsms/LSMS 2013/UGA_2013/AGSEC10.dta", clear 
drop HHID
g HHID = substr(hh,1,6) + substr(hh,11,2)
g year_wave = 2013

g capital = (a10q1==2 | a10q1==6 | a10q1==10 | a10q1==15 | a10q1==16 | a10q1==17 | a10q1==18 )
// plough, tractor, chain saw, trailer, cultivator, weeder, planter

bysort HHID: egen farm_capital = sum(a10q1)
bysort HHID: egen heavy_capital = sum(capital)

duplicates drop HHID, force

keep HHID year_wave farm_capital heavy_capital

tempfile w2013
save `w2013'

* 2015 
use "$lsms/LSMS 2015/UGA_2015/AGSEC10.dta", clear 
g year_wave = 2015

g capital = (a10q1==2 | a10q1==6 | a10q1==10 | a10q1==15 | a10q1==16 | a10q1==17 | a10q1==18 )
// plough, tractor, chain saw, trailer, cultivator, weeder, planter

bysort HHID: egen farm_capital = sum(a10q1)
bysort HHID: egen heavy_capital = sum(capital)

duplicates drop HHID, force

keep HHID year_wave farm_capital heavy_capital

tempfile w2015
save `w2015'

* 2018
use "$lsms/LSMS 2018 v2/Agric/AGSEC10.dta", clear 
g HHID = t0_hhid
g year_wave = 2018


g capital = (s10q01a==2 | s10q01a==6 | s10q01a==10 | s10q01a==15 | s10q01a==16 | s10q01a==17 | s10q01a==18 )
// plough, tractor, chain saw, trailer, cultivator, weeder, planter

bysort HHID: egen farm_capital = sum(s10q01a)
bysort HHID: egen heavy_capital = sum(capital)

duplicates drop HHID, force

keep HHID year_wave farm_capital heavy_capital

tempfile w2018
save `w2018'

* Append *
append using `w2011'
append using `w2013'
append using `w2015'


merge 1:m HHID year_wave using `lsms'
drop _m


*---------------------------------------------------------------------
* Other cleaning
*---------------------------------------------------------------------

* Create parcel identifier *
g parcelid=.
replace parcelid=A2aq2 if (year_wave==2005 | year_wave==2009) & A2aq2~=.
replace parcelid=A2bq2 if (year_wave==2005 | year_wave==2009) & A2bq2~=.
replace parcelid=parcelID if (year_wave==2011 | year_wave==2013 | year_wave==2015| year_wave == 2018) & parcelID~=.
replace parcelid=prcid if year_wave==2010

duplicates tag HHID parcelid year_wave, generate(dup)

duplicates drop HHID parcelid year_wave,  force // should not have duplicate parcels in each year_wave

* create weights *
g weight = Hmult if year_wave==2005
replace weight = wgt09 if year_wave==2009
replace weight = wgt10 if year_wave==2010
replace weight = mult if year_wave==2011
replace weight = wgt if year_wave==2013
replace weight = hwgt_W5 if year_wave==2015
replace weight =  hwgt_W7 if year_wave == 2018

* Creating dispute variable (Only for ownership parcels after 2005!!!) *
merge 1:1 HHID parcelid year_wave using "lsms_dispute_2005" // merge in dispute data from 2005
drop if _m==2 // 108 parcels don't merge out of 5,400
drop _m


g dispute = a2aq25==1
replace dispute=. if  a2aq25==. | a2aq25==3 | a2aq25==4 // weird answers equal to 3 and 4
// Most observations are missing in wave 2010/11 by this measure, so dropping this year
replace dispute = . if year_wave==2010 

g dispute_2005 = A9q9==1
replace dispute_2005=. if A9q9==.

g dispute_2009 = A2aq29==1
replace dispute_2009 = . if A2aq29==.

replace dispute=dispute_2009 if year_wave==2009
replace dispute=dispute_2005 if year_wave==2005 

* title variables
replace title = A2aq25 if year_wave==2009
*replace title = A9q2 if year_wave==2005


* Land area (size) - for owned land, only *
g size = .
replace size = a2aq4 if year_wave>=2010 // GPS measured; not farmer reported (lots of missing)
replace size = A2aq4 if year_wave<=2009

g sizef = .
replace sizef = a2aq5 if year_wave>=2010 // Farmer reported
replace sizef = A2aq5 if year_wave<=2009
replace sizef = 2000 if sizef==20000 & year_wave==2005 // 1 crazy outlier
 

* Creating regional identifiers *
g central = region==1
g east    = region==2
g north	  = region==3
g west	  = region==4

bysort region: tab a2aq7  
replace region=. if region==0

* Creating district identifiers *
ren district district_old
g district=""
replace district=Districtn09 if Districtn09~=""
replace district=district_name if district_name~=""

replace district=proper(district)

// 2009 district names missing
preserve 
use "$lsms/LSMS 2009/UGA_2009/2009_GSEC1.dta", clear 
ren h1aq1 Districtc09
collapse (first) region, by(Districtc09)
local filename = "district_09"
save  `filename', replace 

use "$lsms/LSMS 2005/UGA_2005/2005_GSEC1.dta", clear 
collapse (first) region Districtn09 , by(Districtc09)
destring Districtc09, replace
merge 1:1 region Districtc09 using "district_09"
keep if _m~=2
drop _m

g year_wave=2009
ren Districtc09 h1aq1
ren Districtn09 district_name_09

local filename = "district_name_09"
save  `filename', replace

restore 

merge m:1 h1aq1 year_wave using "district_name_09"
drop _m
replace district=district_name_09 if year_wave==2009
drop district_name_09

* Tenure - current holdings *
replace own=0 if own==.


* Tenure - user rights *
replace user=0 if user==.



* Tenure - current holdings *
replace own=0 if own==.

g tenure_own = A2aq7 if A2aq7~=.
replace tenure_own = tenure_own_2018 if year_wave == 2018
replace tenure_own = a2aq7 if a2aq7~=.
replace tenure_own=. if tenure_own>4 // other and typos



g mailo_own=tenure_own==3
replace mailo_own=. if tenure_own==.

g freehold_own=tenure_own==1
replace freehold_own=. if tenure_own==.

g leasehold_own=tenure_own==2
replace leasehold_own=. if tenure_own==.

g customary_own=tenure_own==4
replace customary_own=. if tenure_own==.


* Tenure - user rights *
replace user=0 if user==.

g tenure_user = A2bq7 if A2bq7~=.
replace tenure_user = a2bq7 if a2bq7~=.
replace tenure_user=. if tenure_user>4 // other and typos

g mailo_user=tenure_user==3
replace mailo_user=. if tenure_user==.

g freehold_user=tenure_user==1
replace freehold_user=. if tenure_user==.

g leasehold_user=tenure_user==2
replace leasehold_user=. if tenure_user==.

g customary_user=tenure_user==4
replace customary_user=. if tenure_user==.




* Creating district by year identifier
replace year=2005 if year_wave==2005
replace year=2010 if year_wave==2010 & year==.
replace year=2013 if year_wave==2013 & year==.
replace year=2015 if year_wave==2015 & year==.
replace year=2018 if year_wave==2018 & year==.

egen distid = group(district)
g district_year = distid*year_wave

* Assigning label values *
label define mailol 1 "Mailo" 
label values mailo_own mailol

label define yearl 2005 "2005" 2009 "2009" 2010 "2010" 2011 "2011" 2012 "2012" 2013 "2013" 2014 "2014"  2015 "2015" 2016 "2016"  2018 "2018"
label values year yearl 

label define year_wavel 2005 "2005/06" 2009 "2009/10" 2010 "2010/11" 2011 "2011/12" 2013 "2013/14" 2015 "2015/16"  2018 "2018/2019"
label values year_wave year_wavel 


*******************************************************************************
* Land titles of occupancy for mailo land
*******************************************************************************
egen punique = group(parcelid HHID) // unique parcel id

replace district = "Luwero" if district == "Luweero"
replace district = "Sembabule" if district == "Ssembabule"
replace district = "Pader" if district == "Agago"
replace district = "Kotido" if district == "Abim"
replace district = "Lira" if district == "Alebtong"
replace district = "Lira" if district == "Amolatar"
replace district = "Nakapiripirit" if district == "Amudat"
replace district = "Gulu" if district == "Amuru" | district == " Amuru"
replace district = "Mbale" if district == "Bududa" | district == "Buduuda"
replace district = "Iganga" if district == "Bugweri"
replace district = "Bushenyi" if district == "Behweju" | district == "Buhweju"
replace district = "Mukono" if district == "Buikwe"
replace district = "Kumi" if district == "Bukedea"
replace district = "Masaka" if district == "Bukomansimbi"
replace district = "Kapchorwa" if district == "Bukwo"
replace district = "Sironko" if district == "Bulambuli"
replace district = "Masindi" if district == "Buliisa"
replace district = "Kabarole" if district == "Bunyangabu"
replace district = "Tororo" if district == "Butaleja"
replace district = "Mpigi" if district == "Butambala"
replace district = "Kamuli" if district == "Buyende"
replace district = "Lira" if district == "Dokolo"
replace district = "Mpigi" if district == "Gomba"
replace district = "Mbarara" if district == "Ibanda"
replace district = "Pallisa" if district == "Butebo"
replace district = "Kibaale" if district == "Kagadi"
replace district = "Kibaale" if district == "Kakumiro"
replace district = "Apac" if district == "Kwania"
replace district = "Gulu" if district == "Omoro"
replace district = "Kabale" if district == "Rubanda"
replace district = "Manafwa" if district == "Namisindwa"
replace district = "Kabale" if district == "Rukiga"
replace district = "Rakai" if district == "Kyotera"
replace district = "Nakapiripirit" if district == "Nabilatuk"
replace district = "Mubende" if district == "Kassanda"
replace district = "Hoima" if district == "Kikuube"
replace district = "Masaka" if district == "Kalungu"
replace district = "Pallisa" if district == "Kibuku"
replace district = "Masindi" if district == "Kiryandongo"
replace district = "Apac" if district == "Kole"
replace district = "Kapchorwa" if district == "Kween"
replace district = "Kiboga" if district == "Kyankwanzi"
replace district = "Kyenjojo" if district == "Kyegegwa"
replace district = "Kitgum" if district == "Lamwo"
replace district = "Iganga" if district == "Luuka"
replace district = "Masaka" if district == "Lwengo"
replace district = "Rakai" if district == "Lyantonde"
replace district = "Mbale" if district == "Manafwa"
replace district = "Arua" if district == "Maracha"
replace district = "Bushenyi" if district == "Mitooma"
replace district = "Bugiri" if district == "Namayingo"
replace district = "Iganga" if district == "Namutumba"
replace district = "Moroto" if district == "Napak"
replace district = "Kumi" if district == "Ngora"
replace district = "Bundibugyo" if district == "Ntoroko"
replace district = "Amuru" if district == "Nwoya"
replace district = "Arua" if district == "Nyadri"
replace district = "Lira" if district == "Otuke"
replace district = "Apac" if district == "Oyam"
replace district = "Nebbi" if district == "Pakwach"
replace district = "Pallisa" if district == "Palisa"
replace district = "Bushenyi" if district == "Rubirizi"
replace district = "Soroti" if district == "Serere"
replace district = "Bushenyi" if district == "Sheema"
replace district = "Nebbi" if district == "Zombo"
replace district = "Katakwi" if district == "Amuria"
replace district = "Kamuli" if district == "Kaliro"
replace district = "Mbarara" if district == "Kiruhura"
replace district = "Arua" if district == "Koboko"
replace district = "Mubende" if district == "Mityana"
replace district = "Luwero" if district == "Nakaseke"
replace district = "Kotido" if district == "Kaabong"
replace district = "Pallisa" if district == "Budaka"
replace district = "Mbarara" if district == "Isingiro"
replace district = "Katakwi" if district == "Kapelebyong"


gen buganda = 1 if  district == "Kiboga" | district == "Luwero" | district == "Luweero" | district == "Mukono" | district =="Kampala" | district == "Mpigi" | district == "Mubende" | district == "Masaka" | district == "Rakai"

replace buganda = 0 if buganda == .

gen borderbuganda = 1 if district == "Kibaale" | district == "Hoima" | district == "Masindi" | district == "Kamuli" | district == "Jinja" | district == "Kabarole" | district == "Mbarara"

replace borderbuganda = 0 if borderbuganda == .

replace buganda=1 if (h1aq1==102 | h1aq1==103 |  h1aq1==104 |  h1aq1==105 |  h1aq1==106 |  h1aq1==107 |  h1aq1==108 |  h1aq1==110) 

replace borderbuganda=1 if h1aq1==204 | h1aq1==205 |  h1aq1==403 |  h1aq1==405 |  h1aq1==409 |  h1aq1==410 


* Using mailo from the census *
merge m:1 district using "$tenure"

keep if _m==3  

keep HHID punique district district_name distid own user district_code county_name county_code subcounty_name subcounty_code urban year region dispute ///
yearoftitle  parcelID title mailo* freehold* leasehold* customary* buganda borderbuganda year_wave parcelid weight tenure_own tenure_user size sizef farm_capital heavy_capital


* Saving and erasing data *
encode(district), gen(districtid)

save "$lsms/lsms_panel_merged211117.dta", replace

foreach i in 2005 2009 2010 2011 2013 2015 2018 {
	erase lsms_own_`i'.dta
	erase lsms_user_`i'.dta

}
erase lsms_dispute_2005.dta
erase district_09.dta
erase district_name_09.dta

egen std_mailoc = std(mailo_census) // why are we taking std of this? SW: thought it would be easier to interpret for 1SD change in share of mailo land
label var std_mailoc "% Mailo"
label var mailo_census "% Mailo"
gen zero = 0

bysort districtid: gen number = _N
drop if number < 10
drop if district == "Kampala" | district == "Nakasongo"

*************** CLEANING TITLE INFO THAT IS INCONSISTENT **********************
order HHID parcelid year_wave title 
sort HHID parcelid year_wave

bysort HHID parcelid: g diff = (title==4 & title[_n-1]~=4 & year_wave==2015)
bysort HHID parcelid: g diff2 = (title==4 & title[_n-2]~=4 & year_wave==2018)

replace title = title[_n-1] if year_wave==2015 & diff==1
replace title = title[_n-2] if year_wave==2018 & diff2==1


// 1 = certificate of title; 2 = certificate of cutsomary; 3 = certificate of occupancy
g cert_title = title==1
g cert_cust = title==2
g cert_occup = title==3
g notitle = title==4
 

foreach v of varlist cert* notitle {
	replace `v' = . if title==.
}

gen anycert = cert_title == 1 | cert_cust == 1 | cert_occup == 1 
replace anycert = . if cert_title == .

save "$dropbox/UgandaPESShareFolder/Data/lsms_panel_jeem.dta", replace


****************** USING ONLY 2018 DATA ************************

replace yearoftitle = . if yearoftitle > 2018
la var yearoftitle "Year parcel granted certificate (2018 data)"
*hist yearoftitle if yearoftitle, bin(20)
*hist yearoftitle if yearoftitle > 1999 & cert_occup == 1, bin(10) xtitle("Year of certificate of occupancy") yscale(range(0 0.15))
*hist yearoftitle if yearoftitle > 1999 & cert_cust == 1, bin(10)  xtitle("Year of certificate of customary tenure") yscale(range(0 0.15)) ylabel(0(.05).15)
*hist yearoftitle if yearoftitle > 1999 & cert_title == 1, bin(10) xtitle("Year of certificate of ownership") yscale(range(0 0.15))

****************** USING ALL DATA ************************
*graph bar (mean) cert_occup, over(year_wave)
*graph bar (mean) anycert, over(year_wave)


*-------------------------------------------------------------------------------
* Looking at behavior change after obtaining a certificate
*-------------------------------------------------------------------------------
label var anycert "Has certificate"

eststo: reghdfe dispute anycert [aw=weight], abs(HHID) keepsing cluster(HHID)
estadd ysumm, mean sd
eststo: reghdfe dispute anycert [aw=weight], abs(HHID year_wave) keepsing cluster(HHID)
estadd ysumm, mean sd

eststo: reghdfe farm_capital anycert [aw=weight], abs(HHID) keepsing cluster(HHID)
estadd ysumm, mean sd
eststo: reghdfe farm_capital anycert [aw=weight], abs(HHID year_wave) keepsing cluster(HHID)
estadd ysumm, mean sd

eststo: reghdfe heavy_capital anycert [aw=weight], abs(HHID) keepsing cluster(HHID)
estadd ysumm, mean sd
eststo: reghdfe heavy_capital anycert [aw=weight], abs(HHID year_wave) keepsing cluster(HHID)
estadd ysumm, mean sd


esttab using "$treetablesuganda/lsms.tex", se b(%12.3f) se(%12.3f) nomtitles nonotes style(tex) label replace fragment nonumbers starlevels(* 0.10 ** 0.05 *** 0.01) sca("ymean Mean DV" "ysd SD DV") keep(anycert) prehead(\begin{tabular}{l*{6}{c}} \hline \hline & (1) & (2) & (3) & (4) & (5) & (6)\\ & \multicolumn{2}{c}{Dispute (0/1)} & \multicolumn{2}{c}{Farm Capital} & \multicolumn{2}{c}{Heavy Capital}\\) posthead(\hline \\) prefoot(\\ Houseld FE: & Y & Y & Y & Y & Y & Y \\ Survey Wave FE: & N & Y & N & Y & N & Y \\ Years: & 2009-19 & 2009-19 & 2011-19 & 2011-19 & 2011-19 & 2011-19 \\) postfoot(\hline \hline \end{tabular} \begin{tablenotes} \item \footnotesize{* p$<$ 0.10, ** p$<$0.05, *** p $<$ 0.01. Fixed effects estimates. Unit of observation is a household in a survey wave of the Uganda National Panel Survey. All estimates control for household fixed effects and weight observations by survey weights. \textit{Farm Capital} is the total number of the following tools owned by the household: hoe, ploughs, pangas, slashers, wheel barrows, tractor, watering cans, pruning knives, pruning saws, chain/band saws, sheller, spade, fork hoe, ox-plough, trailer, cultivator, weeder, planter, sprayer, pail, milk can. \textit{Heavy capital} is the total number of the following tools owned by the household: ploughs, tractor, chain/band saws, trailer, cultivator, weeder, and planter. Standard errors clustered at the household level in parentheses.} \end{tablenotes} )
estimates clear



